from django.db import models


# 定义模型类: Area
class Area(models.Model):

    name = models.CharField(max_length=20, verbose_name='名称')
    # 自关联（特殊的一对多）：生成的字段名 parent——id
    # parent = models.ForeignKey('Area')
    parent = models.ForeignKey('self', on_delete=models.SET_NULL,
                               related_name='subs', null=True,
                               blank=True, verbose_name='上级行政区域')

    class Meta:
        db_table = 'tb_areas'
        verbose_name = '行政区别'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name